/*!
 * Ext JS Library 3.3.1
 * Copyright(c) 2006-2010 Sencha Inc.
 * licensing@sencha.com
 * http://www.sencha.com/license
 */




/*!
 * Ext JS Library 3.3.1
 * Copyright(c) 2006-2010 Sencha Inc.
 * licensing@sencha.com
 * http://www.sencha.com/license
 */
AddSemanticRelationWindow = Ext.extend(Ext.app.Module, {
    id: 'addsemanticrelation-win',
    autostart: false,
    formPanel: null,
    store: null,
    window: null,
    refId: null,
    init: function() {
        this.launcher = {
            text: 'Add Reference',
            iconCls: 'refwin-icon',
            handler: this.createWindow,
            scope: this
        };
    },
    
    onSubmitClick: function() {
    	var semanticRelation = this.formPanel.get(0).getValue();
    	if (!semanticRelation) {
    		alert('Please select a semantic relation!');
    		return;
    	}
    	ReferenceManager.addSemanticRelation(this.refId, semanticRelation, function() {
	    	//alert('Semantic relation has been added: ' + semanticRelation);
	    	Ext.ComponentMgr.get('mydesktop').getModule('ref-win').reloadReferences(null);
	    	Ext.ComponentMgr.get('mydesktop').getModule('graph-win').reloadGraph();
	    });
    	this.window.hide();
    	this.window.close();
    },
    
    createWindow: function(referenceId) {
    	this.refId = referenceId;
//    	rc = this.refContent;
//    	alert('1 ' + rc.url + ' ' + rc.baseXpath + ' ' + rc.slideuri);
    	var myId = 'addref-win_'+new Date().getTime();
        var desktop = this.app.getDesktop();
        var ref = this;
       
        this.formPanel = new Ext.form.FormPanel({
        	items:[
        	    {
        	    	id: 'refSemRel',
        	    	name: 'refSemanticRelation', 
        	    	xtype: 'combo', 
        	    	fieldLabel: 'Select semantic relation',
        	    	editable: true,
        	    	triggerAction:'all',
        	    	mode:'local',
        	    	forceSelection:true,
        	    	allowBlank:false,
        	    	store: new Ext.data.ArrayStore({
        	        	fields: [ 'dataFieldName' ],
				        data: [ ['illustriert'], ['erklaert'], ['erweitert'] ],
				        autoLoad: false
        	        }),
        	    	valueField: 'dataFieldName',
        	    	displayField: 'dataFieldName'
        	    }
        	], 
        	buttons:[{
        		text: 'Add semantic relation',
        		scope: ref,
        		handler: this.onSubmitClick
        	}]
        });
        this.window = desktop.createWindow({
            id: myId,
            title: 'Add Semantic Relation',
            width: 400,
            height: 200,
            x: 250,
            y: 400,
            iconCls: 'refwin-icon',
            shim: false,
            animCollapse: false,
            border: false,
            constrainHeader: true,
            collapsible: true,
            modal:true,
            layout: 'fit',
            items: [ this.formPanel ]
        });
        this.window.show();
     }
});